package com.comment.pojo.domain.logic.core;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.comment.config.dao.typeHandler.*;
import com.comment.util.message.ListUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

/**
 * (CoreSkillEffect)表实体类
 *
 * @author cxy
 * @since 2024-08-21 18:04:41
 */
@ApiModel("技能效果")
@Data
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@TableName(autoResultMap = true)
public class CoreSkillEffect extends Model<CoreSkillEffect> {// swagger2,mybatis-plus
    @TableId(type = IdType.AUTO)
    @ApiModelProperty("id技能独立效果id")
    private Long id;

    @ApiModelProperty("技能id")
    private Long coreSkillId;

    //////////////////////////////////////////////////////  效果和目标
    @TableField(typeHandler = SetLongHandler.class)
    @ApiModelProperty("技能效果类型选择范围")
    private Set<Long> effectTypeId;

    @ApiModelProperty("技能效果类型选择数量")
    private Integer effectTypeNum;

    @ApiModelProperty("目标范围和类型")
    private Integer targetRange;

    @ApiModelProperty("目标条件")
    private Integer targetCondition;
    //////////////////////////////////////////////////////  触发条件
    @ApiModelProperty("本局技能触发第几次")
    private Integer trigger1;

    @ApiModelProperty("第多少回合触发")
    private Integer trigger2;

    @ApiModelProperty("阶段条件")
    private Integer trigger3;

    @ApiModelProperty("战法类型条件")
    @TableField(typeHandler = ListIntegerHandler.class)
    private List<Integer> trigger4;

    @ApiModelProperty("效果类型条件")
    @TableField(typeHandler = ListLongHandler.class)
    private List<Long> trigger5;

    @ApiModelProperty("触发目标")
    private Integer trigger6;

    @ApiModelProperty("生效概率")
    @TableField(typeHandler = ListDoubleHandler.class)
    private List<Double> probability;
    @ApiModelProperty("技能效果触发几率")
    @TableField(exist = false)
    private Double resProbability;

    /**
     * -1 按回合触发
     * 1  按次数触发1次
     * 2  按次数触发2次
     */
    @ApiModelProperty("触发次数")
    private Integer triggerNum;

    @ApiModelProperty("指定生效回合(0准备回合无法指定)")
    private Integer appoint;

    @ApiModelProperty("准备回合")
    private Integer prepare;

    @ApiModelProperty("持续回合")
    private Integer keep;
    ///////////////////////////////////////////////////// 数值
    @ApiModelProperty("基础数值1")
    @TableField(typeHandler = ListDouble2Handler.class)
    private List<Double> baseValue1;
    @TableField(exist = false)
    @ApiModelProperty("技能效果生效数值")
    private Double resDoubleValue1;

    @ApiModelProperty("基础数值2")
    @TableField(typeHandler = ListDoubleHandler.class)
    private List<Double> baseValue2;
    @TableField(exist = false)
    @ApiModelProperty("技能效果生效数值")
    private Double resIntegerValue1;

    @ApiModelProperty("衰弱数值")
    @TableField(typeHandler = ListDouble2Handler.class)
    private List<Double> weakValue1;
    @TableField(exist = false)
    @ApiModelProperty("每回合衰弱数值")
    private Double resDoubleValue2;

    @ApiModelProperty("衰弱数值")
    @TableField(typeHandler = ListDoubleHandler.class)
    private List<Double> weakValue2;
    @TableField(exist = false)
    @ApiModelProperty("每回合衰弱数值")
    private Double resIntegerValue2;

    @ApiModelProperty("基础数值数值累计上限")
    private Integer baseValueMax;

    @ApiModelProperty("叠层上限")
    private Integer layerMax;

    ///////////////////////////////////////////////////////////////////////////////////////////////////////// 序列化版本号
    @TableField(exist = false)
    private static final long serialVersionUID = 849811557988341813L;

    /////////////////////////////////////////////////////////////////////////////////////////////////////////// 获取主键值
    @Override
    public Serializable pkVal() {
        return this.id;
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////// 非数据库
    /**
     * 初始操作
     */
    public CoreSkillEffect init() {
        return this;
    }

    public void obtainNumericalValues(CoreSkillStar coreSkillStar) {
        if (coreSkillStar == null) {
            throw new IllegalArgumentException("Skill star cannot be null");
        }
        Integer skillStar = coreSkillStar.getSkillStar();
        resProbability = ListUtil.getDoubleOrDefault(probability, skillStar, 0.0);
        resIntegerValue1 = ListUtil.getDoubleOrDefault(baseValue2, skillStar, 0.0);
        resDoubleValue1 = ListUtil.getDoubleOrDefault(baseValue1, skillStar, 0.0);
        resIntegerValue2 = ListUtil.getDoubleOrDefault(weakValue2, skillStar, 0.0);
        resDoubleValue2 = ListUtil.getDoubleOrDefault(weakValue1, skillStar, 0.0);
    }

    public List<Integer> obtainNumberOfEffectiveRounds(Integer roundCount) {
        List<Integer> numberOfEffectiveRounds = new ArrayList<>();
        Integer appoint = getAppoint();

        Integer keep = getKeep();
        if (appoint > 0) {
            for (Integer i = 0; i < keep; i++) {
                numberOfEffectiveRounds.add(i + appoint);
            }
        }

        Integer prepare = getPrepare();
        if (appoint == 0) {
            for (Integer i = 0; i < keep; i++) {
                numberOfEffectiveRounds.add(i + roundCount + prepare);
            }
        }
        return numberOfEffectiveRounds;
    }
}
